﻿@{
    ViewBag.Title = "Document";
    Layout = "~/Views/Share/_Layout.cshtml";
}
@section css{


}

@section scripts{
    <script src="~/Content/grid/src/noke.grid.edit.js"></script>
    
    <script>
        $(function () {
            InitControlEvent();
        });

        function InitControlEvent() {
            $('#btnSearch').click(function (e) {
                BubbleEvent(e, 'A', function (tag) {
                    var searchby = $(tag).attr('title');
                    BindData(searchby);
                });
            });
            $('#btnAdd').click(function (e) {
                BubbleEvent(e, 'BUTTON', function (tag) {
                    var col = $.trim($('#txtColumnName').val()).toString().toLocaleLowerCase();
                    if (col.length <= 0) {
                        return false;
                    }
                    var model = { ColumnName: col, Description: col, IsUsed: true, ColumnType: 'varchar', Length: 20, TableName: 'Product', IsNull:false, DefaultValue:'' };

                    var url = '/Doc/SetTable/';
                    $.post(url, model, function (res) {
                        if (res.Code == 100) {
                            $('#txtName').val(col);
                            BindData('Column');
                        } else {
                            console.log(res.Msg);
                        }
                    }, 'json');
                });
            });
        }

        function BindData(searchby) {
            var name = $('#txtName').val().toString().toLocaleLowerCase();
            var url = '/Doc/GetTableListBy' + searchby + '/' + name;

            $.getJSON(url, function (res) {
                if (res.Code == 100) {
                    var setting = GetGridSetting();
                    setting.data = res.Value;
                    $('#' + setting.id).grid(setting);
                } else {
                    console.log(res.Msg);
                }
            }, 'json');
        }

        function GetGridSetting() {
            //debugger;
            //alert($('#chkEdit').attr('checked'));

            var setting = { id: "DataGrid", key: "Id", title: {}, cols: [], toolbar: {}, rowindex: true, data: [], supportdata: {}, editable: false };
            setting.editable = document.getElementById('chkEdit').checked;
           // setting.cols.push({ key: "Id", type: "string", width: 80, label: "ObjectId" });
            setting.cols.push({ key: "TableName", type: "string", width: 160, label: "表名", edittype: 'text' });
            setting.cols.push({ key: "ColumnName", type: "string", width: 160, label: "字段名", edittype: 'text' });
            setting.cols.push({ key: "ColumnType", type: "string", width: 120, label: "数据类型", edittype: 'ddbox' });
            setting.cols.push({ key: "Length", type: "string", width: 80, label: "数据长度", edittype: 'text' });
            setting.cols.push({ key: "DefaultValue", type: "string", width: 120, label: "默认值", edittype: 'text' });
            setting.cols.push({ key: "IsUsed", type: "string", width: 100, label: "是否有用", edittype: 'ddbox' });
            setting.cols.push({ key: "IsNeedAduit", type: "string", width: 100, label: "需审核", edittype: 'ddbox' });
            setting.cols.push({ key: "IsChangeByBasic", type: "string", width: 100, label: "主商品修改", edittype: 'ddbox' });
            setting.cols.push({ key: "Description", type: "string", width: 300, label: "描述", edittype: 'text' });
            setting.cols.push({ key: "OrderNumber", type: "string", width: 80, label: "排序", edittype: 'text' });
            setting.cols.push({ key: "IsNull", type: "string", width: 100, label: "可为空", edittype: 'ddbox' });
            
            setting.supportdata = { ColumnType: [], IsUsed: [{ value: '是', key: true }, { value: '否', key: false }], IsChangeByBasic: [{ value: '是', key: true }, { value: '否', key: false }], IsNeedAduit: [{ value: '是', key: true }, { value: '否', key: false }], IsNull: [{ value: '是', key: true }, { value: '否', key: false }] };
            setting.supportdata.ColumnType = [{ value: 'int', key: 'int' }, { value: 'smallint', key: 'smallint' }, { value: 'bigint', key: 'bigint' }, { value: 'nvarchar', key: 'nvarchar' }, { value: 'varchar', key: 'varchar' }, { value: 'varchar(max)', key: 'varchar(max)' }, { value: 'nvarchar(max)', key: 'nvarchar(max)' }, { value: 'bit', key: 'bit' }, { value: 'datetime', key: 'datetime' }, { value: 'date', key: 'date' }, { value: 'decimal', key: 'decimal' }];

            setting.rowbind = function (i, model, args) {
                model['PlatformImg'] = 'demo/' + model.SysNo + '.png';
                model['ColumnType-value'] = model.ColumnType;
                model['IsUsed-value'] = model.IsUsed ? '是' : '否';
                model['IsNull-value'] = model.IsNull ? '是' : '否';
                model['IsNeedAduit-value'] = model.IsNeedAduit ? '是' : '否';
                model['IsChangeByBasic-value'] = model.IsChangeByBasic ? '是' : '否';
            };

            setting.save = function (model, args) {
                var url = '/Doc/SetTable/';
                $.post(url, model, function (res) {
                    if (res.Code == 100) {
                        console.log('change ' + res.Msg);
                        $('#txtName').val(model.ColumnName);
                        BindData('Column');
                    } else {
                        console.log('change ' + res.Msg);
                    }
                }, 'json');
            };

            return setting;
        }

        function BubbleEvent(e, tagName, callback) {
            e = e || window.event;
            var target = e.target || e.srcElement;
            if (target.nodeName.toString().toUpperCase() == tagName.toUpperCase()) {
                callback(target);
            }
        }
    </script>
   
}

@section head{
        
        <div class="col-sm-4">
            <ol class="breadcrumb">
                <li>
                    <a href="/">Home</a>
                </li>
                <li>
                    <a href="/">Tools</a>
                </li>
                <li class="active">
                    <strong>数据库表结构</strong>
                </li>
            </ol>
        </div>

}

<div class="row">
    <div class="col-lg-3">
        <div class="panel input-group" id="btnSearch" style="height">
            <input id="txtName" type="text" class="form-control" placeholder="表名称或字段名称">
            <div class="input-group-btn">
                <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" type="button"><i class="fa fa-search"></i> 查询 <span class="caret"></span></button>
                <ul class="dropdown-menu pull-right">
                    <li><a href="#" title="Table">表名</a></li>
                    <li><a href="#" title="Column">字段名</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="col-lg-2">
        <div class="panel input-group" id="btnAdd">
            <input id="txtColumnName" type="text" class="form-control" placeholder="字段名称">
            <div class="input-group-btn">
                <button class="btn btn-primary" type="button"><i class="fa fa-plus"></i> 添加 </button>
            </div>
        </div>
    </div>
    <div class="col-lg-5">
    </div>
    <div class="col-lg-2">
        <div class="checkbox m-r-xs">
            <input type="checkbox" id="chkEdit"  />
            <label for="chkEdit">是否可编辑</label>
        </div>
    </div>
    <div class="col-lg-12">
        <div class="panel">
            <div id="DataGrid"></div>
        </div>
    </div>
</div>
<!-- /.row -->

<!--
    
                        var data = ['Warranty,nvarchar(200),TRUE,保修条款(B2C),'
                                        , 'PackageList,nvarchar(500),TRUE,包装清单,'
                                        , 'Weight,int,FALSE,重量,0'
                                        , 'C3SysNo,int,FALSE,工业类目小类SysNo,'
                                        , 'ManufacturerSysNo,int,TRUE,供应商SysNo,'
                                        , 'ProductLink,nvarchar(200),TRUE,商品链接,'
                                        , 'MultiPicNum,int,FALSE,图片数量,0'
                                        , 'PMUserSysNo,int,TRUE,商品管理人SysNo,'
                                        , 'PPMUserSysNo,int,TRUE,采购管理人SysNo,'
                                        , 'APMUserSysNo,int,TRUE,APM人SysNo,'
                                        , 'CreateUserSysNo,int,FALSE,创建人SysNo,'
                                        , 'CreateTime,datetime,FALSE,创建时间,getdate()'
                                        , 'Attention,varchar(max),TRUE,加减乘厨,'
                                        , 'Note,nvarchar(500),TRUE,备注,'
                                        , 'BarCode,nvarchar(300),TRUE,条形码,'
                                        , 'Status,int,FALSE,状态 : 0,有效,1,展示,-1,作废,'
                                        , 'IsLarge,int,FALSE,是否贴条,0'
                                        , 'LastVendorSysNo,int,TRUE,最后供应商SysNo,'
                                        , 'AvgDailyClick,int,TRUE,平均每日点击量,5'
                                        , 'AssessmentTitle,nvarchar(200),TRUE,网上评测信息标题,'
                                        , 'AssessmentLink,nvarchar(200),TRUE,网上评测信息链接,'
                                        , 'VirtualArriveTime,int,TRUE,虚库到货时间,'
                                        , 'InventoryCycleTime,int,TRUE,库存周转天数,'
                                        , 'DMSWeight,decimal(18,2),TRUE,DMS权重系数,'
                                        , 'DMS,decimal(18,2),TRUE,DMS,'
                                        , 'OPL,int,TRUE,,'
                                        , 'OrderNum,int,TRUE,顺序,'
                                        , 'ProductColor,int,TRUE,商品颜色,'
                                        , 'ProductSize,int,TRUE,商品大小,'
                                        , 'DefaultVendorSysNo,int,TRUE,默认供应商SysNo,'
                                        , 'DefaultPurchasePrice,decimal(19,6),TRUE,默认采购价格,'
                                        , 'Product2ndType,int,TRUE,主子商品类型 : 0,普通商品,'
                                        , 'MasterProductSysNo,int,TRUE,主商品SysNo,'
                                        , 'IsCanPurchase,int,TRUE,,'
                                        , 'PromotionTimeFrom,datetime,TRUE,促销开始时间,'
                                        , 'PromotionTimeTo,datetime,TRUE,促销结束时间,'
                                        , 'IsCanDoVat,int,TRUE,,1'
                                        , 'ProducingArea,nvarchar(50),TRUE,产地,'
                                        , 'PackQuantity,int,TRUE,包装数量,'
                                        , 'MinOrderQuantity,int,TRUE,起订量,'
                                        , 'IsStoreFrontSale,int,TRUE,门店是否销售,'
                                        , 'SaleUnit,nvarchar(50),TRUE,销售单位,'
                                        , 'StorageDay,int,TRUE,货架期,'
                                        , 'VERSION,timestamp,TRUE,,'
                                        , 'IsInStock,int,FALSE,是否代销,1'
                                        , 'Keywords,nvarchar(300),TRUE,关键字,'
                                        , 'ProductAssociateSysNo,int,TRUE,关联商品SysNo,'
                                        , 'SaleType,int,FALSE,销售类型,0'
                                        , 'Volume,decimal(19,6),FALSE,体积,0'
                                        , 'OnlineShowType,int,FALSE,展现方式,1'
                                        , 'ISInstall,int,FALSE,是否安装,0'
                                        , 'WarrantyDescription,ntext,TRUE,保修详细说明(B2C),'
                                        , 'Avgscore,int,FALSE,评论平均分,3'
                                        , 'HasFlash,int,FALSE,是否有动画,0'
                                        , 'BaseNumber,int,FALSE,销售基数,0'
                                        , 'SEOTitle,nvarchar(200),TRUE,SEO标题,'
                                        , 'SEOKeyword,nvarchar(250),TRUE,SEO关键词,'
                                        , 'SEODescription,nvarchar(400),TRUE,SEO描述,'
                                        , 'LimitArea,int,TRUE,限购地区 : 0,不限,1,福建省,2,厦门,3,厦漳泉,'
                                        , 'ISListShow,int,FALSE,是否列表显示,1'
                                        , 'IsInvoice,int,FALSE,是否开票,1'
                                        , 'IsVirtual,int,TRUE,是否虚拟,'
                                        , 'MsgTemplate,nvarchar(500),TRUE,短信模板,'
                                        , 'Long,decimal(19,6),FALSE,长,0'
                                        , 'Width,decimal(19,6),FALSE,宽,0'
                                        , 'HIGH,decimal(19,6),FALSE,高,0'
                                        , 'IsDirectSend,int,FALSE,是否直送,0'
                                        , 'OldProductID,nvarchar(50),TRUE,维智系统商品号,'
                                        , 'SynStatus,int,FALSE,同步状态,0'
                                        , 'ReceiveStatus,int,FALSE,,0'
                                        , 'IsBulkStock,int,TRUE,是否大宗商品,'
                                        , 'IsThePlan,int,TRUE,是否计划内,'
                                        , 'BiddingDesc,nvarchar(2000),TRUE,核心卖点,'
                                        , 'IsGOnlineShow,int,FALSE,是否前台显示(G),0'
                                        , 'ISCreateSN,int,FALSE,是否生成SN,0'
                                        , 'WarrantyB2G,nvarchar(200),TRUE,保修条款(B2G),'
                                        , 'WarrantyDescriptionB2G,varchar(max),TRUE,保修详细说明(B2G),'
                                        , 'WarrantyB2B,nvarchar(200),TRUE,保修条款(B2B),'
                                        , 'WarrantyDescriptionB2B,varchar(max),TRUE,保修详细说明(B2B),'
                                        , 'FinanceType,int,FALSE,财务类型,0'
                                        , 'IsGiftCard,int,TRUE,是否是礼品卡,'
                                        , 'IsNewProduct,int,TRUE,是否新品,'
                                        , 'SaleQty,int,TRUE,销量,'
                                        , 'UpdateNewProductTime,datetime,TRUE,更新新品时间,'
                                        , 'saleweekqty,int,TRUE,周销量,'
                                        , 'GiftCardLotSysNo,int,TRUE,礼金卡模板SysNo,'
                                        , 'OnlineDateTime,datetime,FALSE,上线时间,getdate()'
                                        , 'IsInBuy,int,FALSE,是否内部购机,0'
                                        , 'StorageMethods,int,FALSE,商品存储方式,0'
                                        , 'IsValuable,int,FALSE,是否贵重商品,0'
                                        , 'OnlineShowTypes,nvarchar(20),TRUE,展现类型 : 1,正常,2,新品,3,热卖,4,特价,5,售完,6,预售,7,宴客,'
                                        , 'BoxSpecifications,int,FALSE,箱规,1'
                                        , 'ProductSensitivity,int,FALSE,商品敏感度 : 0,价格敏感型商品,1,价格需求敏感型商品,2,非价格敏感性商品,0'
                                        , 'ProductGrade,int,FALSE,商品等级 : 0,A,0,否,1,B,1,是,2,C,3,D,0'
                                        , 'Tag,int,FALSE,标签2 : 0,正常,1,有机,2,进口,3,当季,4,绿色,5,高山,6,高原,7,台湾,8,预售,1'
                                        , 'IsReturn,int,FALSE,是否允许退货,1'
                                        , 'Detect,nvarchar(50),FALSE,是否检测 : 1,本来质检,2,全程冷链,3,买手认证,4,基地直供,'
                                        , 'ShowInList,int,FALSE,是否列表显示,1'
                                        , 'ProductStorageDay,nvarchar(200),TRUE,保质期提醒,'
                                        , 'Tag3,int,TRUE, ,'
                                        , 'FreeCollocationList,nvarchar(200),TRUE,随心配,'
                                        , 'isFreeCollocation,int,FALSE,是否随心配,0'
                                        , 'ShelfLife,int,FALSE,商品保质期（天）,0'
                                        , 'IsOnlinePayonly,int,FALSE,只支持在线支付,0'
                                        , 'isAutoVirtualToReal,int,FALSE,自动虚变实,0'
                                        , 'Tips,varchar(max),TRUE,商品提示,'
                                        , 'IsEasyHome,int,TRUE,是否为宅配,0'
                                        , 'EasyHomeDeliveryTimes,int,TRUE,宅配送次数,0'
                                        , 'IsPayToday,int,FALSE,是否为当天支付,0'
                                        , 'WarningDay,int,FALSE,临期天数（天）,0'
                                        , 'IsUseCoupon,int,FALSE,支持优惠券,1'
                                        , 'DeliveryParttern,int,FALSE,商品配送方式 : 0,常温,1,冷藏,10,常温配送,2,冷冻,3,超低温,4,包装,5,常温包装,6,冷藏包装,7,冷冻包装,8,超低温包装,9,大品,0'
                                        , 'MainSortWeight,int,FALSE,排序权重,0'
                                        , 'ProductPosition,int,FALSE,商品定位 : 0,主力商品-形象性,1,主力商品-独特性,2,主力商品-季节性,3,辅助商品,0'
                                        , 'ProductPopularity,int,FALSE,商品畅销度 : 0,重点促销商品,1,畅销品,2,普通商品,3,滞销品,0'
                                        , 'IsPresell,int,FALSE,是否预售,0'
                                        , 'SKUSign,nvarchar(30),TRUE,SKU标记,'
                                        , 'WebSiteSysNo,int,FALSE,站点SysNo,1'
                                        , 'SplitOrder,int,TRUE,是否允许拆单,0'
                                        , 'Nationwide,int,TRUE,是否允许全国配送,0'
                                        , 'NewMultiPicNum,int,FALSE,商品图片数量,0'
                                        , 'PMGroupOriginSysNo,int,TRUE,原产地PMSysNo,'
                                        , 'AreaGroupSysNo,int,TRUE,全省配规则SysNo,'
                                        , 'DeliveryAreaGroupSysNo,int,TRUE,,'
                                        , 'IsArrivalDay,int,TRUE,是否支持当日达,'
                                        , 'UpdateCount,int,TRUE,更新次数,'
                                        , 'ISDMS,int,TRUE,是否计算DMS,0'
                                        , 'LastUpdateTime,datetime,TRUE,最后更新时间,getdate()'
                                        , 'ApplyRangeType,int,TRUE,适用范围,'
                                        , 'Expected_Days,int,TRUE,预计到货天数,0'
                                        , 'IsNeedProcessing,int,TRUE,是否需加工,0'
                                        , 'ReviewCount,int,TRUE,商品评论数,0'
                                        , 'MerchantSysNo,int,TRUE,入注商家系统编号 : 1,本来生活网,2,爱鲜蜂,3,广东跨境购,4,宁波跨境购,1'
                                        , 'IsPersonalizedPackaging,int,TRUE,是否个性包装,0'
                                        , 'IsProductOrigin,int,TRUE,是否原产地,0'
                                        , 'ProductAttr,int,TRUE,物料属性,0'
                                        , 'CurrencySysNo,int,TRUE,币种SysNo,1'
                                        , 'UpdateTime,datetime,TRUE,更新时间,getdate()'
                                        , 'IsFirstOrders,int,TRUE,,'
                                        , 'ProductOldID,nvarchar(50),TRUE,旧商品ID,'
                                        , 'MainStockSysNo,int,TRUE,主仓号,'
                                        , 'ChannelSysNo,int,TRUE,销售渠道SysNo,'
                                        , 'ProductBasicSysNo,int,TRUE,主商品SysNO,'
                                        , 'IsDelete,bit,TRUE,是否删除,0'
                                        , 'AuditStatus,smallint,TRUE,审核状态,'
                                        , 'IsAlwaysPurchase,bit,TRUE,是否永续采购,'
                                        , 'IsBooking,bit,TRUE,是否可预售,'
                                        , 'BookingNO,int,TRUE,可预售数量,'
                                        , 'ProcessiType,int,TRUE,加工类型,'
                                        , 'GrossWeight,int,TRUE,毛重,'];

                        $(data).each(function (i, item) {
                            var arr = item.split(',');
                            if (arr.length >= 3) {
                                var ty = arr[1].replace(')', '').split('(');

                                var model = { ColumnName: arr[0], IsUsed: true, ColumnType: ty[0], TableName: 'Product', IsNull: false, DefaultValue: '', Description: arr[0], Length: 0 };
                                if (ty[0] != 'decimal' && ty.length == 2)
                                    model.Length = arr[1];
                                if (ty[0] == 'decimal' && ty.length == 2 && arr[1].split(',').length == 2)
                                    model.Length = arr[1].split(',')[1];
                                if (arr.length >= 3)
                                    model.IsNull = arr[2] == 'TRUE';
                                if (arr.length >= 4)
                                    model.Description = arr[3];
                                if (arr.length >= 5)
                                    model.DefaultValue = arr[4];

                                var url = '/Doc/SetTable/';
                                $.post(url, model, function (res) {
                                    if (res.Code == 100) {
                                        $('#txtName').val(col);
                                        BindData('Column');
                                    } else {
                                        console.log(res.Msg);
                                    }
                                }, 'json');
                                //Description: col,Length: 20, 
                            }
                        });
    
    
    -->